﻿using Max.Ph5_2009A.NewShopping.EFCore;
using Max.Ph5_2009A.NewShopping.IRespository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.Ph5_2009A.NewShopping.Respository
{
    public class UnitOfWork : IUnitOfWork
    {
        PH52009ANewShoppingDbContext _context;
        public UnitOfWork(PH52009ANewShoppingDbContext context)
        {
            _context = context;
        }

        /// <summary>
        /// 获取上下文对象
        /// </summary>
        /// <returns></returns>
        public PH52009ANewShoppingDbContext GetDbContext()
        {
            return _context;
        }

        /// <summary>
        /// 提交到数据库（同步）
        /// </summary>
        /// <returns></returns>
        public int SaveChanges()
        {
           return _context.SaveChanges();
        }


        /// <summary>
        /// 提交到数据库（同步）
        /// </summary>
        /// <returns></returns>
        public Task<int> SaveChangesAsync()
        {
            return _context.SaveChangesAsync();
        }
    }
}
